﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsKiHieu
    {
        private double mDenSo = 0.0;
        private double mGiaTri = 0.0;
        private string mMauHoaDon = "";
        private string mSoKiHieu = "";
        private double mTuSo = 0.0;

        public bool DelData(string pKhoa)
        {
            IDataParameter parameter = null;
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "DELETE FROM DM_ViTri WHERE Khoa = '" + pKhoa.Trim() + "'";
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }) > 0;
                flag = flag2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DelDSKiHieu(string pMauHoaDon)
        {
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "DELETE FROM HT_SoKiHieu WHERE MauHoaDon = '" + pMauHoaDon.Trim() + "'";
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]) > 0;
                flag = flag2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Load(string pMauHoaDon)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM HT_KiHieu WHERE MauHoaDon = '" + pMauHoaDon.Trim() + "' ORDER BY SoKiHieu";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mMauHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mSoKiHieu = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mGiaTri = Conversions.ToDouble(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetDecimal));
                    this.mTuSo = Conversions.ToDouble(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetDecimal));
                    this.mDenSo = Conversions.ToDouble(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetDecimal));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[5];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@MauHoaDon", DbType.Int64, ParameterDirection.Input, this.mMauHoaDon);
                commandParameters[1] = DBHelper.createParameter("@SoKiHieu", DbType.Int64, ParameterDirection.Input, this.mSoKiHieu);
                commandParameters[2] = DBHelper.createParameter("@GiaTri", DbType.Date, ParameterDirection.Input, this.mGiaTri);
                commandParameters[3] = DBHelper.createParameter("@TuSo", DbType.Date, ParameterDirection.Input, this.mTuSo);
                commandParameters[4] = DBHelper.createParameter("@DenSo", DbType.Date, ParameterDirection.Input, this.mDenSo);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "HT_sp_KiHieu", commandParameters) > 0;
                flag2 = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public DataTable ShowList(string strCondition)
        {
            DataTable table;
            string commandText = "";
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " AND " + strCondition;
                }
                commandText = " SELECT * FROM HT_SoKiHieu WHERE 1 = 1 " + str2 + " ORDER BY SoKiHieu ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool TrungMa(string strKiHieu, string strMauHoaDon)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM HT_SoKiHieu WHERE RTRIM(MauHoaDon) = '" + strMauHoaDon.Trim() + "' AND RTRIM(SoKiHieu) <> '" + strKiHieu.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public bool WasUsed(string pMauHoaDon, string pSoKiHieu)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM HT_DangKyHoaDon WHERE RTRIM(MauHoaDon) = '" + pMauHoaDon.Trim() + "' and RTRIM(SoKiHieu) = '" + pSoKiHieu.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public double DenSo
        {
            get
            {
                return this.mDenSo;
            }
            set
            {
                this.mDenSo = value;
            }
        }

        public double GiaTri
        {
            get
            {
                return this.mGiaTri;
            }
            set
            {
                this.mGiaTri = value;
            }
        }

        public string MauHoaDon
        {
            get
            {
                return this.mMauHoaDon;
            }
            set
            {
                this.mMauHoaDon = value;
            }
        }

        public string SoKiHieu
        {
            get
            {
                return this.mSoKiHieu;
            }
            set
            {
                this.mSoKiHieu = value;
            }
        }

        public double TuSo
        {
            get
            {
                return this.mTuSo;
            }
            set
            {
                this.mTuSo = value;
            }
        }
    }
}

